﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

///<summary>
///
///</summary>
public class AudioManager
{
    static AudioManager instance;
    AudioSource SoundSource;
    private AudioManager() { }
	AudioSource MusciSource;
    public static AudioManager GetInstance
    {
		get
		{
			if (instance == null)
			{
				instance = new AudioManager();
			}
			return instance;
		}
    }
	public void Init()
	{
		if (!GameObject.Find("Audio").GetComponent<AudioSource>())
		{
			GameObject.Find("Audio").AddComponent<AudioSource>();
			SoundSource = GameObject.Find("Audio").GetComponent<AudioSource>();
		}
		else
			SoundSource = GameObject.Find("Audio").GetComponent<AudioSource>();
		MusciSource = GameObject.Find("Audio").GetComponent<Transform>().GetChild(0).GetComponent<AudioSource>();
		PlayerPrefs.SetInt("OpenBGM", 1);
		PlayerPrefs.SetInt("OpenSound", 1);
	}
	
    public void Play(string path)
    {
		if (GameConfig.OpenOrCloseSound)
		{
			AudioClip clip = Resources.Load<AudioClip>(path);
			SoundSource.PlayOneShot(clip);
		}
	}

	public void SoundStop()
	{
		SoundSource.Stop();
		AudioClip clip = Resources.Load<AudioClip>("Sounds/Panel/click_start");
		SoundSource.PlayOneShot(clip);
	}

	public void PlayBGMusic()
	{
		if (GameConfig.OpenOrCloseBGM)
		{
			MusciSource.Play();
		}
	}

	public void MusicStop()
	{
		MusciSource.Stop();
	}

}
